/**
 * 
 */
package com.gr.staffpm.form.validation;

import org.apache.wicket.validation.IValidatable;
import org.apache.wicket.validation.IValidator;
import org.apache.wicket.validation.ValidationError;


/**
 * @author Graham Rhodes 26 May 2011 20:31:36
 */
public class ProjectKeyValidator implements IValidator<String> {

    private static final long serialVersionUID = 1L;
    private final int maxLength;

    public ProjectKeyValidator(int maxLength) {
        this.maxLength = maxLength;
    }

    /* (non-Javadoc)
     * @see org.apache.wicket.validation.IValidator#validate(org.apache.wicket.validation.IValidatable)
     */
    @Override
    public void validate(IValidatable<String> validatable) {
        if (validatable.getValue().length() > maxLength) {
            ValidationError ve = new ValidationError();
            ve.setMessage("Project Key must be under " + maxLength + " characters.");
            validatable.error(ve);
        }
    }


}
